<template>
  <div>
    <h1>{{ ip }}</h1>
    <div>
      <router-link to="/home"
        ><el-button type="primary">返回主页</el-button></router-link
      >
    </div>
  </div>
</template>
<script>
import axios from "axios";

export default {
  name: "Ip",
  data() {
    return {
      ip: "",
      city: "",
      isp: "",
    };
  },
  created() {
    console.log("created");
    this.getIp();
  },

  methods: {
    getIp() {
      console.log("getIp");
      axios
        .get("https://ipv4.icanhazip.com")
        .then((res) => {
          console.log("公网ip 1");
          //console.log(res);
          //console.log(res.data);
          if (res.data) {
            this.ip = res.data;
            console.log("公网ip 2");
            console.log(res.data);
          }
        })
        .catch((e) => {
          console.log(eval);
        });
    },
  },
};
</script>
<style scoped></style>
